import request from '@/utils/request'

export function getMenusTree(pid) {
  return request({
    url: 'api/menus/lazy?pid=' + pid,
    method: 'get'
  })
}

export function getMenus(params) {
  return request({
    url: 'api/menus',
    method: 'get',
    params
  })
}

export function getMenuSuperior(ids) {
  const data = ids.length || ids.length === 0 ? ids : Array.of(ids)
  return request({
    url: 'api/menus/superior',
    method: 'post',
    data
  })
}

export function getChild(id) {
  return request({
    url: 'api/menus/child?id=' + id,
    method: 'get'
  })
}

export function buildMenus(flag) {
  return request({
    url: 'admin/menu/list/'+flag,
    method: 'get'
  })
}

export function add(data) {
  return request({
    url: 'api/menus',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'api/menus',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'api/menus',
    method: 'put',
    data
  })
}

/**
 * 菜单分页
 */
export function menusPage(query) {
  return request({
    url: 'admin/menu/page',
    method: 'get',
    params: query
  })
}

/**
 * 获取子菜单
 */

export function subMenus(obj) {
  return request({
    url: 'admin/menu/sub-compontents',
    method: 'post',
    data: obj
  })
}

/**
 * 添加菜单
 */
export function saveMenus(obj) {
  return request({
    url: 'admin/menu/save',
    method: 'post',
    data: obj
  })
}

/**
 * 修改菜单
 */
export function editMenus(obj) {
  return request({
    url: 'admin/menu/edit',
    method: 'post',
    data: obj
  })
}

/**
 * 菜单删除
 */
export function delMenus(obj) {
  return request({
    url: 'admin/menu/delete',
    method: 'post',
    data: obj
  })
}

/**
 * 获取当前菜单父菜单id
 */
export function getParentId(obj) {
  return request({
    url: 'admin/menu/get-parent-id',
    method: 'post',
    data: obj
  })
}




export function getParentInfo(menuId) {
  return request({
    url: 'admin/menu/get-parent-info/'+menuId,
    method: 'get'
  })
}




export default { add, edit, del, getMenusTree, getMenuSuperior, getMenus, getChild,menusPage,getParentId,getParentInfo }
